package cn.com.thingo.hyintelligent.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.th.opensdk.openapi.RoomInfo;

import java.util.List;

import cn.com.thingo.hyintelligent.R;


public class AreaSpinnerAdapter extends BaseAdapter {
    private List<RoomInfo> list;
    private LayoutInflater inflater;

    public AreaSpinnerAdapter(Context context, List<RoomInfo> list) {
        this.list = list;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView textView;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_area_spinner, parent, false);
            textView = convertView.findViewById(R.id.spinner_item_area);
            convertView.setTag(textView);
        } else {
            textView = (TextView) convertView.getTag();
        }
        textView.setText(list.get(position).getRoomName());
        return convertView;
    }
}
